<template>
  <div class="report-form-content">
    <van-tabs :active="active1" type="card" :animated="true" :swipeable="true">
      <van-tab title="合同借阅">
        <div class="report-form-list-content">
          <div class="shenpilist" v-if="contract">
            <label>合同名称：</label>
            <span>{{ contract.name }}</span>
          </div>
          <div class="shenpilist" v-if="contract">
            <label>合同负责人：</label>
            <span>{{ showIdLabel(userList, contract.userId, 'name') }}</span>
          </div>
          <div class="shenpilist" v-if="obj">
            <label>借阅人</label>
            <span>{{ showIdLabel(userList, obj.borrowUserId, 'name') }}</span>
          </div>
          <div class="shenpilist"  v-if="obj">
            <label>借阅人</label>
            <span>{{ showIdLabel(organizationList, obj.borrowDepartmentId, 'organizationName') }}</span>
          </div>
          <div class="shenpilist"  v-if="obj">
            <label>借阅类型</label>
            <span>{{ obj.borrowType === '1' ? '纸质' : '电子'  }}</span>
          </div>
          <div class="shenpilist">
            <label>备注</label>
          </div>
          <div class="shenpilist" v-if="obj">
            <span>{{ obj.remark }}</span>
          </div>
        </div>
      </van-tab>
      <van-tab title="合同详情">
        <contractMainDetail v-if="obj" :contractInitialId="obj.contractInitialId" />
      </van-tab>
    </van-tabs> 
  </div>
</template>
<script setup>
import {ref, watch} from 'vue'
import {doGet} from "@/config/http";
import {svc, showIdLabel, getListPageSize} from "@/config/common";
import { useRoute, useRouter } from 'vue-router'
import contractMainDetail from '@/h5/components/contractMainDetail.vue'
import initListStore from '@/store/modules/initList'

const router = useRouter()
const route = useRoute()

const props = defineProps({
  contractBorrowingId: {
    required: true,
    type: String,
  }
})
let active1 = ref(0)
let obj = ref(null)

let contract = ref(null)

let contractTypeList = initListStore().contractTypeList // 合同类型
let contractCooperationList = initListStore().contractCooperationList // 往来单位
let contractFeetypeList = initListStore().contractFeetypeList // 合同费用类型
let contractTemplateList = initListStore().contractTemplateList // 合同模版
let bankList = initListStore().bankList // 银行
let userList = initListStore().userList // 用户
let governmentList = initListStore().governmentList //  政府单位
let organizationList = initListStore().organizationList // 部门
let contractSignerList = initListStore().contractSignerList // 签订人
let contractFiletypeList = initListStore().contractFiletypeList // 合同附件类型

// const initList = async () => {
//   let p1 = doGet(svc, '/contract-type/page', {pageSize: getListPageSize()}, false) // 合同类型
//   let p2 = doGet(svc, '/contract-cooperation/page', {pageSize: getListPageSize()}, false) // 往来单位
//   let p3 = doGet(svc, '/contract-feetype/page', {pageSize: getListPageSize()}, false) // 合同费用类型
//   let p4 = doGet(svc, '/contract-template/page', {pageSize: getListPageSize()}, false) // 合同模版
//   let p5 = doGet(svc, '/bank/page', {pageSize: getListPageSize()}, false) // 银行
//   let p6 = doGet(svc, '/user/page', {pageSize: getListPageSize()}, false) // 用户
//   let p7 = doGet(svc, '/government/page', {pageSize: getListPageSize()}, false) //  政府单位
//   let p8 = doGet(svc, '/organization/page', {pageSize: getListPageSize()}, false) // 部门
//   let p9 = doGet(svc, '/contract-signer/page', {pageSize: getListPageSize()}, false) // 签订人
//   let p10 = doGet(svc, '/contract-filetype/page', {pageSize: getListPageSize()}, false) // 合同附件类型

//   let resArray = await Promise.all([p1, p2, p3, p4, p5, p6, p7, p8, p9, p10])
//   contractTypeList.value = resArray[0]['records']
//   contractCooperationList.value = resArray[1]['records']
//   contractFeetypeList.value = resArray[2]['records']
//   contractTemplateList.value = resArray[3]['records']
//   bankList.value = resArray[4]['records']
//   userList.value = resArray[5]['records']
//   governmentList.value = resArray[6]['records']
//   organizationList.value = resArray[7]['records']
//   contractSignerList.value = resArray[8]['records']
//   contractFiletypeList.value = resArray[9]['records']
// }

const initObj = async (val) =>  {
  if (val) {
    obj.value = await doGet(svc, `/contract-initial-borrow/${val}`, {}, true)
    contract.value = await doGet(svc, '/contract-initial/' + obj.value.contractInitialId, {}, false)
  }
}

watch(() => props.contractBorrowingId, async val => {
  await initObj(val)
  // await initList()
},{immediate:true})

</script>

<style scoped lang="scss">
.report-form-content {
  width: 100%;
  height: 52vh;
  overflow-x: hidden;
  overflow-y: auto;
  margin-top: 1.25rem;
}
.update-log {
  width: 100%;
  margin: 30px 0;
}
.tabs-form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tabs-form-head span {
  font-size: 18px;
  color: #303133;
  font-weight: bold;
}
.shenpilist {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--van-cell-background);
  box-sizing: border-box;
  width: 100%;
  padding: var(--van-cell-vertical-padding) var(--van-cell-horizontal-padding);
  overflow: hidden;
  color: var(--van-cell-text-color);
  font-size: var(--van-cell-font-size);
  // line-height: var(--van-cell-line-height);
  border-bottom: 1px solid var(--van-border-color);;
  & label {
    color: var(--van-field-label-color);
    // text-align: left;
    word-wrap: break-word;
    font-weight: 700;
  }
  & span {
    display: block;
    box-sizing: border-box;
    // width: 100%;
    color: var(--van-field-input-text-color);
    line-height: inherit;
    // text-align: left;
    background-color: transparent;
    border: 0;
    resize: none;
    -webkit-user-select: auto;
    user-select: auto;
  }
}
</style>
